# Maintainer: nixfloyd <nixfloyd@gmail.com>
pkgname=prometheus-snmp-exporter
_pkgname=snmp_exporter
pkgver=0.25.0
pkgrel=0
pkgdesc="SNMP Exporter for Prometheus"
url="https://github.com/prometheus/snmp_exporter"
# riscv64: prometheus/procfs needs updating
arch="all !riscv64"
license="Apache-2.0"
makedepends="go net-snmp-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-openrc"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/prometheus/snmp_exporter/archive/v$pkgver.tar.gz
	snmp-exporter.initd
	snmp-exporter.confd
	"
builddir="$srcdir/$_pkgname-$pkgver"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go build -o bin/snmp_exporter
	go build -o bin/generator ./generator
}

check() {
	go test
}

package() {
	install -Dm755 bin/snmp_exporter \
		"$pkgdir"/usr/bin/snmp_exporter
	install -Dm755 bin/generator \
		"$pkgdir"/usr/bin/snmp_exporter-generator
	install -Dm644 snmp.yml \
		"$pkgdir"/etc/prometheus/snmp.yml
	install -Dm644 -t "$pkgdir"/usr/share/doc/prometheus-snmp-exporter/ \
		README.md
	install -Dm644 -t "$pkgdir"/usr/share/doc/prometheus-snmp-exporter/examples/ \
		generator/generator.yml
	install -Dm644 -t "$pkgdir"/usr/share/doc/prometheus-snmp-exporter/generator/ \
		generator/README.md
	install -m755 -D "$srcdir"/snmp-exporter.initd \
		"$pkgdir"/etc/init.d/snmp-exporter
	install -m644 -D "$srcdir"/snmp-exporter.confd \
		"$pkgdir"/etc/conf.d/snmp-exporter
}

sha512sums="
29beb903ecd2520232eb8a3c398be4728622256ceb863b5c2587f520a52547fc29b2646de4fb44686bfdade7e7fec4199d29294b6806437ec22b801addc2e1ea  prometheus-snmp-exporter-0.25.0.tar.gz
a11085f14e192ff277107dbbb12857a3043dbce1acadbbdf94a88d2b921745f9556cad3c0a81a0113349d322e02b1705831967af3ecc0f95259e759ade9ff5ad  snmp-exporter.initd
489cb298e215bd9647aa5293d456106eb26a73f5fbd9d42fab68de26d273ebb612dba01ba113ce58521b543a2f82a10ad86dc35056ef8d0438b39e77be61f67e  snmp-exporter.confd
"
